In [2]:
import numpy as np
from StringIO import StringIO
In [79]:
!head wine_names.csv
In [71]:
data = np.genfromtxt("wine_names.csv", dtype=None, delimiter=',', skip_header=1)
In [3]:
data = np.genfromtxt("wine_names.csv", dtype=float, delimiter=',', skip_header=1)
In [4]:
data
Out[4]:
Data is from:
ndarray.ndim > the number of axes (dimensions) of the array. In the Python world, the number of dimensions is referred to as rank. (Commentary: This is not = dimensions (columns)??
ndarray.shape > the dimensions of the array. This is a tuple of integers indicating the size of the array in each dimension. For a matrix with n rows (Reihen) and m columns (Spalten), shape will be (n,m). The length of the shape tuple is therefore the rank, or number of dimensions, ndim.
ndarray.size > the total number of elements of the array. This is equal to the product of the elements of shape.
ndarray.dtype > an object describing the type of the elements in the array. One can create or specify dtype's using standard Python types. Additionally NumPy provides types of its own. numpy.int32, numpy.int16, and numpy.float64 are some examples.
In [73]:
data.shape
Out[73]:
177 rows and 14 columns, 177 datapoints with 14 dimensions
In [74]:
data.ndim
Out[74]:
In [128]:
np.set_printoptions(threshold='nan')
Print everything ↑
In [75]:
np.set_printoptions(edgeitems=3,infstr='inf',
linewidth=75, nanstr='nan', precision=8,
suppress=False, threshold=1000, formatter=None)
Default settings ↑
In [90]:
data[10]
Out[90]:
In [92]:
data[:,1]
Out[92]:
first value (index [0, n]) of second dimension [n, 1] = second column
In [103]:
data[0,1]
Out[103]:
second value (index [1, n]) of second dimension [n, 1] = second column
In [104]:
data[1,1]
Out[104]:
Before that some basics about the communication between ipython and SC3 via OSC.
Download pyOSC here: https://trac.v2.nl/wiki/pyOSC And do sudo ipython setup.py install inside the pyOSC folder.
On OSC more here: http://opensoundcontrol.org/introduction-osc
Source: http://www.caseyanderson.com/teaching/ipython-to-supercollider-via-osc/
In [26]:
import OSC
import time, random
client = OSC.OSCClient()
client.connect( ( '127.0.0.1', 57110 ) )
In [66]:
msg = OSC.OSCMessage()
msg.setAddress("s_new")
msg.append("grain")
msg.append(-1)
msg.append(0)
msg.append(1)
msg.append("amp")
msg.append(1)
msg.append("freq")
msg.append(4000)
msg.append("sustain")
msg.append(0.1)
msg.append("pan")
msg.append(0)
client.send(msg)
In [186]:
import time, sys
for i in range(100):
msg = OSC.OSCMessage()
msg.setAddress("s_new")
msg.append("grain")
msg.append(-1)
msg.append(0)
msg.append(1)
msg.append("amp")
msg.append(1)
msg.append("freq")
msg.append(440+(i*10))
msg.append("sustain")
msg.append(0.15)
msg.append("pan")
msg.append(1)
client.send(msg)
msg = OSC.OSCMessage()
msg.setAddress("s_new")
msg.append("grain")
msg.append(-1)
msg.append(0)
msg.append(1)
msg.append("amp")
msg.append(1)
msg.append("freq")
msg.append(1440+(i*10))
msg.append("sustain")
msg.append(0.15)
msg.append("pan")
msg.append(-1)
client.send(msg)
time.sleep(0.04)
In [188]:
def oscgrain( frequency ):
msg = OSC.OSCMessage()
msg.setAddress("s_new")
msg.append("grain")
msg.append(-1)
msg.append(0)
msg.append(1)
msg.append("amp")
msg.append(1)
msg.append("freq")
msg.append(frequency) #read in data points
msg.append("sustain")
msg.append(0.015) #0.01-0.04
msg.append("pan")
msg.append(-1)
client.send(msg)
In [190]:
oscgrain(1000)
In [4]:
data[0,1]
Out[4]:
reading out one data point
In [194]:
data[1,:]
Out[194]:
In [130]:
import time, sys
for i in range (14):
print data[1,i]
time.sleep(0.4)
reading-out one dimension
In [153]:
data[:,1]
Out[153]:
In [154]:
np.amax((data[:,1]))
Out[154]:
In [156]:
np.amin((data[:,1]))
Out[156]:
In [178]:
np.amax((data[:,1]))-np.amin((data[:,1]))
Out[178]:
In [14]:
dimension = 12
datanew = (data[:,dimension] - np.amin((data[:,dimension]))) / (np.amax((data[:,dimension]))-np.amin((data[:,dimension])))
In [15]:
datanew
Out[15]:
In [6]:
data0 = (data[:,0] - np.amin((data[:,0]))) / (np.amax((data[:,0]))-np.amin((data[:,0])))
data1 = (data[:,1] - np.amin((data[:,1]))) / (np.amax((data[:,1]))-np.amin((data[:,1])))
data2 = (data[:,2] - np.amin((data[:,2]))) / (np.amax((data[:,2]))-np.amin((data[:,2])))
In [17]:
data_all = np.column_stack([data0, data1, data2])
In [5]:
data_all = (data - np.min(data, axis=0))/(np.max(data, axis=0) - np.min(data, axis=0))
or
In [15]:
mn, mx = data.min(0), data.max(0)
data_all = (data - mn)/(mx-mn)
In [6]:
data_all
Out[6]:
In [14]:
data_sc3 = 16+(data_all*22450)
In [17]:
np.savetxt("wine_data_scaled.csv", data_sc3, delimiter=",")
In [13]:
data_all.shape
Out[13]:
In [19]:
data_all[1,:]
Out[19]:
In [20]:
data[1,:]
Out[20]:
In [22]:
import time, sys
for i in range (14):
print data[1,i]
time.sleep(0.4)
In [170]:
import time, sys
for i in range (14):
print data_all[1,i]
time.sleep(0.4)
In [214]:
import time, sys
for i in range(14):
oscgrain(200+(1500*data_all[123,i]))
time.sleep(0.09)
In [215]:
for i in range(178):
for ii in range (14):
oscgrain(200+(1500*data_all[i,ii]))
time.sleep(0.01) # 14*0.01=0.14 lenght/period time
time.sleep(0.2)
is this related to parallel coordinate visualization?
combine "read in and play/sonify one datapoint n dimensions" with brushing in scatteplot matrix?
In [74]:
%load_ext version_information
%version_information numpy, scipy, matplotlib, sympy, pyosc
Out[74]:
In [ ]: